<template>
  <div class="bigBox">
    <div class="centerBox">
      <div class="boxHead">延期申请</div>
        <div class="box_body">
          <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="延期时间" required>
            <el-form-item prop="delayTime">
              <el-date-picker
                v-model="ruleForm.delayTime"
                type="date"
                placeholder="选择日期" value-format="timestamp">
              </el-date-picker>
            </el-form-item>
        </el-form-item>
       
        <el-form-item label="延期事由" prop="delayReason">
          <el-input type="textarea" v-model="ruleForm.delayReason" :autosize="{ minRows: 2, maxRows: 4}"  placeholder="请输入延期事由"></el-input>
        </el-form-item>
        <el-form-item class="btnBox">
          <el-button type="primary" @click="submitForm('ruleForm')"
            >确定</el-button
          >
          <el-button @click="resetForm('ruleForm')">取消</el-button>
        </el-form-item>
      </el-form>
        </div>
    </div>
  </div>
</template>

<script>

import {askFor} from "@/api/case.js";
export default {
  name: "DispatchDialog2",
  // components: { UploadFile },
  props: ['id','code'],
  data() {
    return {
      ruleForm: {
        delayTime: "",
        delayReason: "",
        caseCode:'',
        caseId:'',
      },
      rules: {
        delayTime: [{
            type: "date",
            required: true,
            message: "请选择日期",
            trigger: "change",
          }],
        delayReason: [{ required: true, message: "请填写延期事由", trigger: "change" }],
      },
    };
  },
  created() {
    this.ruleForm.caseCode = this.code
    this.ruleForm.caseId = this.id

  },
  methods: {
    submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            askFor(this.ruleForm).then((result) => {
            console.log(result)
            if (result.code == 200 || result.code == '200') {
                this.$message({
                  message: '申请成功',
                  type: 'success'
                });
                setTimeout(()=>{
                    this.resetForm('ruleForm')
                })
            }else if(result.code == 501 || result.code == '501'){
               this.$message({
                  message: '申请失败，推送失败',
                  type: 'success'
                });
            }else if(result.code == 500 || result.code == '500'){
              this.$message({
                message: '申请失败，已经申请过',
                type: 'success'
              });
            }
          })
          .catch((res) => {
            console.log("wwwwww")
             console.log(result)
          });
          } else {

            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
        this.$emit('childFn');
      }
  },
};
</script>

<style lang="scss" scoped>
.bigBox {
  position: fixed;
  width: 100%;
  height: 100%;
  top: 0;
  left: 0;
  background-color: rgba(0, 0, 0, 0.3);
  z-index: 2000;
  .centerBox{
    width: 460px;
    height: 300px;
    position: absolute;
    top: 50%;
    left: 50%;
    margin-top: -150px;
    margin-left: -230px;
    background-color: #fff;
    border-radius: 4px;
    .boxHead{
      height: 46px;
      background-color: #127ce4;
      color: #fff;
      font-size: 14px;
      line-height: 46px;
      padding: 0 16px;
      border-radius: 4px 4px 0 0;
    }
    .box_body{
      margin-top: 12px;
      padding: 16px;
      .el-date-editor.el-input{
        width: 100%;
      }
      .btnBox{
        margin-top: 60px;
      }
    }
  }
}
</style>
